/*
 * File:   TessMetaInfoTest.cpp
 * Author: Guilherme Monteiro
 *
 */

#include "TessMetaInfoTest.h"

CPPUNIT_TEST_SUITE_REGISTRATION(TessMetaInfoTest);

TessMetaInfoTest::TessMetaInfoTest() {
}

TessMetaInfoTest::~TessMetaInfoTest() {
}

void TessMetaInfoTest::setUp() {
    this->path = "/books/caracterizacao/metadados/tabelasAlta/image278_0.png";
    
    this->dotdot = "..";
    
    this->bar = "/";
    
    this->books = "books";
    this->bookName = "caracterizacao";
    this->pageName = "image278_0";
    this->pageName2 = "image278";
    this->baixaResolucao = "baixa_resolucao";
    this->altaResolucao = "alta_resolucao";
    this->tabelasAlta = "tabelasAlta";
    this->tabelasBaixa = "tabelasBaixa";
    this->metadados = "metadados";
    this->transcriptions = "transcricoes";
    this->userAnswer = "respostaUsuarioTT";
    this->texts = "texts";
    this->taxes = "confidences";
    
    this->tessMetaInfo = new TessMetaInfo(path);
}

void TessMetaInfoTest::tearDown() {
}

void TessMetaInfoTest::testTessMetaInfo1() {
    string highTablePath = "";
    
    try {
        TessMetaInfo* tessMetaInfo = new TessMetaInfo(highTablePath);
    }
    catch(NullImageException nie) {
        string message = "ERROR ==> Image " + highTablePath + " can't be loaded. Change the image path or the directory of execution";
        if (strcmp(message.c_str(), nie.what()) != 0) {
             CPPUNIT_ASSERT(false);
        }
    }
    catch(exception e) {
        cerr << e.what() << endl;
    }
}

void TessMetaInfoTest::testTessMetaInfo2() {
    string highTablePath = "/books/image1000.png";
    try {
        TessMetaInfo* tessMetaInfo = new TessMetaInfo(highTablePath);
    }
    catch(NullImageException nie) {
        string message = "ERROR ==> Image " + highTablePath + " can't be loaded. Change the image path or the directory of execution";
        if (strcmp(message.c_str(), nie.what()) != 0) {
             CPPUNIT_ASSERT(false);
        }
    }
    catch(exception e) {
        cerr << e.what() << endl;
    }
}

void TessMetaInfoTest::testGetTIFFImagePath() {
    string result = tessMetaInfo->getTIFFImagePath();
    string expect = dotdot + bar + books + bar + bookName + bar + metadados +
            bar + tabelasAlta + bar + pageName + ".tiff";
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TessMetaInfoTest::testGetTranscriptionPath() {
    string result = tessMetaInfo->getTranscriptionPath();
    string expect = dotdot + bar + books + bar + bookName + bar + transcriptions + 
            bar + pageName + ".txt";
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TessMetaInfoTest::testGetUserAnswerPath() {
    string result = tessMetaInfo->getUserAnswerPath();
    string expect = dotdot + bar + books + bar + bookName + bar + metadados +
            bar + userAnswer + bar + pageName + ".txt";
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TessMetaInfoTest::testGetLowResolutionImagePath() {
    string result = tessMetaInfo->getLowResolutionImagePath();
    //printf("result: %s\n", result.c_str());
    string expect = dotdot + bar + books + bar + bookName + bar +
            baixaResolucao + bar + pageName2 + ".png";
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TessMetaInfoTest::testGetHighResolutionImagePath() {
    string result = tessMetaInfo->getHighResolutionImagePath();
    //printf("result: %s\n", result.c_str());
    string expect = dotdot + bar + books + bar + bookName + bar +
            altaResolucao + bar + pageName2 + ".png";
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TessMetaInfoTest::testGetHighResolutionTablePath() {
    string result = tessMetaInfo->getHighResolutionTablePath();
    string expect = dotdot + bar + books + bar + bookName + bar + metadados + bar + 
            tabelasAlta + bar + pageName + ".png";
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TessMetaInfoTest::testGetLowResolutionTablePath() {
    string result = tessMetaInfo->getLowResolutionTablePath();
    string expect = dotdot + bar + books + bar + bookName + bar + metadados + bar + 
            tabelasBaixa + bar + pageName + ".png";
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TessMetaInfoTest::testGetOutputTaxesFileName() {
    string result = tessMetaInfo->getOutputConfidencesFileName();
    //printf("result: %s\n", result.c_str());
    string expect = dotdot + bar + books + bar + bookName + bar + transcriptions + bar + taxes + bar + pageName + ".txt";
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}

void TessMetaInfoTest::testGetOutputTextsFileName() {
    string result = tessMetaInfo->getOutputTextsFileName();
    //printf("result: %s\n", result.c_str());
    string expect = dotdot + bar + books + bar + bookName + bar + transcriptions + bar + texts + bar + pageName + ".txt";
    if (strcmp(result.c_str(), expect.c_str()) != 0) {
        CPPUNIT_ASSERT(false);
    }
}